import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  }
]
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
// 异步路由
export const asyncRouterMap = [
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'system' },
    children: [
      {
        path: 'role',
        name: 'system-role',
        component: () => import('@/views/system/role'),
        meta: { title: '权限', icon: 'role',
          permissions: ['roles.index', 'roles.update', 'roles.destroy', 'roles.store'] }
      },
      {
        path: 'admin',
        name: 'system-admin',
        component: () => import('@/views/system/admin'),
        meta: { title: '管理员', icon: 'admin',
          permissions: ['admins.index', 'admins.update', 'admins.store', 'admins.destroy'] }
      },
      {
        path: 'admin-log',
        name: 'system-admin-log',
        component: () => import('@/views/system/admin-log'),
        meta: { title: '操作日志', icon: 'log',
          permissions: ['admin-logs.index'] }
      }
    ]
  },
  {
    path: '/wechat',
    component: Layout,
    meta: { title: '微信设置', icon: 'wechat' },
    children: [
      {
        path: 'menu',
        name: 'wechat-menu_menu',
        component: () => import('@/views/wechat/menu'),
        meta: {
          title: '自定义菜单', icon: 'wechatMenu',
          permissions: ['wechat-menus.store', 'wechat-menus.update', 'wechat-menus.destroy', 'wechat-groups.index', 'wechat-groups.store', 'wechat-groups.update', 'wechat-groups.show']
        }
      },
      {
        path: 'message',
        name: 'wechat-messages',
        component: () => import('@/views/wechat/message'),
        meta: {
          title: '消息管理',
          icon: 'msg',
          permissions: ['wechat-messages.index', 'wechat-messages.store', 'wechat-messages.update', 'wechat-messages.destroy']
        }
      },
      {
        path: 'media',
        name: 'wechat-medias',
        component: () => import('@/views/wechat/media'),
        meta: { title: '素材管理', icon: 'wechatMedia', permissions: ['wechat-medias.index'] }
      }
    ]
  },
  {
    path: '/school',
    component: Layout,
    meta: { title: '学校管理', icon: 'school' },
    children: [
      {
        path: 'school',
        name: 'school-list',
        component: () => import('@/views/school/school'),
        meta: {
          title: '学校列表', icon: 'school-list',
          permissions: ['schools.index', 'schools.store', 'schools.update', 'school-rules.update']
        }
      },
      {
        path: 'school-admin',
        name: 'school-admin',
        component: () => import('@/views/school/school-admin'),
        meta: {
          title: '管理员', icon: 'admin',
          permissions: ['school-admins.index', 'school-admins.store', 'school-admins.update', 'school-admins.refresh']
        }
      },
      {
        path: 'school-admin-log',
        name: 'school-admin-log',
        component: () => import('@/views/school/school-admin-log'),
        meta: {
          title: '操作日志', icon: 'log',
          permissions: ['school-admin-logs.index']
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    meta: { title: '用户管理', icon: 'user' },
    children: [
      {
        path: 'list',
        name: 'user_list',
        component: () => import('@/views/user/list'),
        meta: { title: '用户列表', icon: 'list',
          permissions: ['users.index', 'users.update', 'users.store', 'users.destroy'] }
      },
      {
        path: 'role',
        name: 'user-role',
        component: () => import('@/views/user/role'),
        meta: { title: '用户角色', icon: 'user_role',
          permissions: ['user-roles.index', 'user-roles.update', 'user-roles.store', 'user-roles.destroy'] }
      }
    ]
  },
  {
    path: '/food',
    component: Layout,
    meta: { title: '菜品管理', icon: 'food' },
    children: [
      {
        path: 'food-list',
        name: 'food_list',
        component: () => import('@/views/food/list'),
        meta: { title: '菜品列表', icon: 'list',
          permissions: ['foods.index'] }
      },
      {
        path: 'food-type',
        name: 'food-type-list',
        component: () => import('@/views/food/type'),
        meta: { title: '菜品种类', icon: 'type',
          permissions: ['food-types.index'] }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    meta: { title: '订单管理', icon: 'order' },
    children: [
      {
        path: 'order-list',
        name: 'order_list',
        component: () => import('@/views/order/list'),
        meta: { title: '订单列表', icon: 'list',
          permissions: ['book-rules.index', 'book-orders.index'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

